package com.zhilei.mq;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 使用MQ生成简历消息的生产者
 *
 * @author 志磊
 */
@Configuration
public class InitResumeMQConfig {

    public static final String INIT_RESUME_EXCHANGE = "init_resume_exchange";

    public static final String INIT_RESUME_QUEUE = "init_resume_queue";

    public static final String ROUTING_KEY_INIT_RESUME = "zhilei.init.resume";

    // 声明一个交换机
    @Bean(INIT_RESUME_EXCHANGE)
    public Exchange exchange() {
        return ExchangeBuilder
                .topicExchange(INIT_RESUME_EXCHANGE)
                .durable(true)
                .build();
    }

    // 声明一个队列
    @Bean(INIT_RESUME_QUEUE)
    public Queue queue() {
        return QueueBuilder
                .durable(INIT_RESUME_QUEUE)
                // TODO 设置超时时间
                // .withArgument("x-message-ttl", 10 * 1000)
                .build();
    }

    // 将队列和交换机绑定
    @Bean
    public Binding initResumeBinding(@Qualifier(INIT_RESUME_EXCHANGE) Exchange exchange,
                                     @Qualifier(INIT_RESUME_QUEUE) Queue queue) {
        return BindingBuilder
                .bind(queue)
                .to(exchange)
                .with("zhilei.init.#")
                .noargs();
    }

}


















